#include "imgui/DutEditor.h"

bool ImGui::DutEditor::ShowTexture2D(const Dut::Texture2D& inst, const ImVec2 &sz)
{
	bool res = false;

	ImTextureID imgTex = inst.m_ShaderResourceView.Get();

	ImGui::Image(imgTex, sz);
	return res;
}

bool ImGui::DutEditor::FreeMove(Dut::Transform& transform, const WorkDesc& desc)
{
	ImGuiIO& io = ImGui::GetIO();

	float deltaTime = io.DeltaTime;

	ImGui::PushID(&transform);
	float frontInput = 0.0f;
	if (ImGui::IsKeyDown(ImGuiKey_W))
	{
		frontInput = 1.0f;
	}
	if (ImGui::IsKeyDown(ImGuiKey_S))
	{
		frontInput = -1.0f;
	}
	float dist = frontInput * desc.walkSpeed * deltaTime;;
	transform.Translate(-dist);

	float turnInput = 0.0f;
	if (ImGui::IsKeyDown(ImGuiKey_A))
	{
		turnInput = 1.0f;
	}

	if (ImGui::IsKeyDown(ImGuiKey_D))
	{
		turnInput = -1.0f;
	}
	float delteRight = turnInput * desc.trunSpeed * deltaTime;

	transform.MoveRight(delteRight);

	if (ImGui::IsMouseDragging(ImGuiMouseButton_Left))
	{
		ImVec2 rotInput = io.MouseDelta;
		float rotX = desc.rotSpeedX * deltaTime * rotInput.x;
		float rotY = desc.rotSpeedY * deltaTime * rotInput.y;

		transform.RotateY(rotX);
		transform.RotateX(rotY);
	}


	ImGui::PopID();


	return false;
}